package com.esri.core.geometry;

import com.esri.core.geometry.Geometry;
import java.io.Serializable;
import java.util.Arrays;

/* loaded from: classes.dex */
public final class Point extends Geometry implements Serializable {
    private static final long serialVersionUID = 2;
    double[] a;

    @Override // com.esri.core.geometry.Geometry
    public int getDimension() {
        return 0;
    }

    public Point() {
        this.m_description = VertexDescriptionDesignerImpl.d();
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public Point(VertexDescription vertexDescription) {
        if (vertexDescription == null) {
            throw new IllegalArgumentException();
        }
        this.m_description = vertexDescription;
    }

    public Point(double d, double d2) {
        this.m_description = VertexDescriptionDesignerImpl.d();
        setXY(d, d2);
    }

    public Point(double d, double d2, double d3) {
        this.m_description = VertexDescriptionDesignerImpl.d();
        Point3D point3D = new Point3D();
        point3D.setCoords(d, d2, d3);
        a(point3D);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public Point2D a() {
        if (l()) {
            throw new GeometryException("This operation should not be performed on an empty geometry.");
        }
        Point2D point2D = new Point2D();
        double[] dArr = this.a;
        point2D.setCoords(dArr[0], dArr[1]);
        return point2D;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void a(Point2D point2D) {
        i();
        setXY(point2D.x, point2D.y);
    }

    Point3D b() {
        if (l()) {
            throw new GeometryException("This operation should not be performed on an empty geometry.");
        }
        Point3D point3D = new Point3D();
        point3D.x = this.a[0];
        point3D.y = this.a[1];
        if (this.m_description.hasZ()) {
            point3D.z = this.a[2];
        } else {
            point3D.z = VertexDescription.getDefaultValue(1);
        }
        return point3D;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void a(Point3D point3D) {
        i();
        boolean e = e(1);
        if (!e && !VertexDescription.isDefaultValue(1, point3D.z)) {
            addAttribute(1);
            e = true;
        }
        if (this.a == null) {
            k();
        }
        this.a[0] = point3D.x;
        this.a[1] = point3D.y;
        if (e) {
            this.a[2] = point3D.z;
        }
    }

    public final double getX() {
        if (l()) {
            throw new GeometryException("This operation should not be performed on an empty geometry.");
        }
        return this.a[0];
    }

    public void setX(double d) {
        a(0, 0, d);
    }

    public final double getY() {
        if (l()) {
            throw new GeometryException("This operation should not be performed on an empty geometry.");
        }
        return this.a[1];
    }

    public void setY(double d) {
        a(0, 1, d);
    }

    public double getZ() {
        return a(1, 0);
    }

    public void setZ(double d) {
        a(1, 0, d);
    }

    public double getM() {
        return a(2, 0);
    }

    public void setM(double d) {
        a(2, 0, d);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public int j() {
        return b(3, 0);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void a(int i) {
        a(3, 0, i);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public double a(int i, int i2) {
        if (l()) {
            throw new GeometryException("This operation was performed on an Empty Geometry.");
        }
        if (i2 >= VertexDescription.getComponentCount(i)) {
            throw new IndexOutOfBoundsException();
        }
        int attributeIndex = this.m_description.getAttributeIndex(i);
        if (attributeIndex >= 0) {
            return this.a[this.m_description.a(attributeIndex) + i2];
        }
        return VertexDescription.getDefaultValue(i);
    }

    int b(int i, int i2) {
        if (l()) {
            throw new GeometryException("This operation was performed on an Empty Geometry.");
        }
        if (i2 >= VertexDescription.getComponentCount(i)) {
            throw new IndexOutOfBoundsException();
        }
        int attributeIndex = this.m_description.getAttributeIndex(i);
        if (attributeIndex >= 0) {
            return (int) this.a[this.m_description.a(attributeIndex) + i2];
        }
        return (int) VertexDescription.getDefaultValue(i);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void a(int i, int i2, double d) {
        i();
        if (VertexDescription.getComponentCount(i) < i2) {
            throw new IndexOutOfBoundsException();
        }
        int attributeIndex = this.m_description.getAttributeIndex(i);
        if (attributeIndex < 0) {
            addAttribute(i);
            attributeIndex = this.m_description.getAttributeIndex(i);
        }
        if (this.a == null) {
            k();
        }
        this.a[this.m_description.a(attributeIndex) + i2] = d;
    }

    void a(int i, int i2, int i3) {
        a(i, i2, i3);
    }

    @Override // com.esri.core.geometry.Geometry
    public Geometry.Type getType() {
        return Geometry.Type.POINT;
    }

    @Override // com.esri.core.geometry.Geometry
    public void setEmpty() {
        i();
        double[] dArr = this.a;
        if (dArr != null) {
            dArr[0] = NumberUtils.NaN();
            this.a[1] = NumberUtils.NaN();
        }
    }

    @Override // com.esri.core.geometry.Geometry
    void c(int i) {
        i();
        if (this.a == null) {
            return;
        }
        int a = this.m_description.a(this.m_description.getAttributeIndex(i));
        int componentCount = VertexDescription.getComponentCount(i);
        int c = this.m_description.c();
        d(c);
        while (true) {
            c--;
            if (c < a + componentCount) {
                break;
            }
            double[] dArr = this.a;
            dArr[c] = dArr[c - componentCount];
        }
        double defaultValue = VertexDescription.getDefaultValue(i);
        for (int i2 = 0; i2 < componentCount; i2++) {
            this.a[a + i2] = defaultValue;
        }
    }

    @Override // com.esri.core.geometry.Geometry
    void b(int i) {
        i();
        if (this.a == null) {
            return;
        }
        int a = this.m_description.a(this.m_description.getAttributeIndex(i));
        int componentCount = VertexDescription.getComponentCount(i);
        int c = this.m_description.c();
        if (c > componentCount) {
            for (int i2 = a + componentCount; i2 < c; i2++) {
                double[] dArr = this.a;
                dArr[i2 - componentCount] = dArr[i2];
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void k() {
        d(this.m_description.c());
        a(this.m_description.b(), this.a, this.m_description.c());
        this.a[0] = NumberUtils.NaN();
        this.a[1] = NumberUtils.NaN();
    }

    @Override // com.esri.core.geometry.Geometry
    public void applyTransformation(Transformation2D transformation2D) {
        if (l()) {
            return;
        }
        Point2D a = a();
        transformation2D.a(a, a);
        a(a);
    }

    @Override // com.esri.core.geometry.Geometry
    void applyTransformation(Transformation3D transformation3D) {
        if (l()) {
            return;
        }
        addAttribute(1);
        a(transformation3D.transform(b()));
    }

    @Override // com.esri.core.geometry.Geometry
    public void copyTo(Geometry geometry) {
        if (geometry.getType() != Geometry.Type.POINT) {
            throw new IllegalArgumentException();
        }
        Point point = (Point) geometry;
        geometry.i();
        if (this.a == null) {
            point.setEmpty();
            point.a = null;
            point.a(this.m_description);
            return;
        }
        point.a(this.m_description);
        point.d(this.m_description.c());
        a(this.a, point.a, this.m_description.c());
    }

    @Override // com.esri.core.geometry.Geometry
    public Geometry createInstance() {
        return new Point(this.m_description);
    }

    @Override // com.esri.core.geometry.Geometry
    public boolean isEmpty() {
        return l();
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public final boolean l() {
        double[] dArr = this.a;
        return dArr == null || NumberUtils.isNaN(dArr[0]) || NumberUtils.isNaN(this.a[1]);
    }

    @Override // com.esri.core.geometry.Geometry
    public void queryEnvelope(Envelope envelope) {
        envelope.setEmpty();
        if (this.m_description != envelope.m_description) {
            envelope.a(this.m_description);
        }
        envelope.merge(this);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    @Override // com.esri.core.geometry.Geometry
    public void queryEnvelope2D(Envelope2D envelope2D) {
        if (l()) {
            envelope2D.setEmpty();
            return;
        }
        envelope2D.xmin = this.a[0];
        envelope2D.ymin = this.a[1];
        envelope2D.xmax = this.a[0];
        envelope2D.ymax = this.a[1];
    }

    @Override // com.esri.core.geometry.Geometry
    void queryEnvelope3D(Envelope3D envelope3D) {
        if (l()) {
            envelope3D.setEmpty();
            return;
        }
        Point3D b = b();
        envelope3D.xmin = b.x;
        envelope3D.ymin = b.y;
        envelope3D.zmin = b.z;
        envelope3D.xmax = b.x;
        envelope3D.ymax = b.y;
        envelope3D.zmax = b.z;
    }

    @Override // com.esri.core.geometry.Geometry
    Envelope1D queryInterval(int i, int i2) {
        Envelope1D envelope1D = new Envelope1D();
        if (l()) {
            envelope1D.setEmpty();
            return envelope1D;
        }
        double a = a(i, i2);
        envelope1D.vmin = a;
        envelope1D.vmax = a;
        return envelope1D;
    }

    private void d(int i) {
        double[] dArr = this.a;
        if (dArr == null) {
            this.a = new double[i];
        } else if (dArr.length < i) {
            double[] dArr2 = new double[i];
            System.arraycopy(dArr, 0, dArr2, 0, dArr.length);
            this.a = dArr2;
        }
    }

    static void a(double[] dArr, double[] dArr2, int i) {
        for (int i2 = 0; i2 < i; i2++) {
            dArr2[i2] = dArr[i2];
        }
    }

    public void setXY(double d, double d2) {
        i();
        if (this.a == null) {
            k();
        }
        double[] dArr = this.a;
        dArr[0] = d;
        dArr[1] = d2;
    }

    public boolean equals(Object obj) {
        if (obj == this) {
            return true;
        }
        if (obj instanceof Point) {
            Point point = (Point) obj;
            if (this.m_description != point.m_description) {
                return false;
            }
            if (l()) {
                return point.l();
            }
            int c = this.m_description.c();
            for (int i = 0; i < c; i++) {
                if (this.a[i] != point.a[i]) {
                    return false;
                }
            }
            return true;
        }
        return false;
    }

    public int hashCode() {
        int hashCode = this.m_description.hashCode();
        if (!l()) {
            int c = this.m_description.c();
            for (int i = 0; i < c; i++) {
                long doubleToLongBits = Double.doubleToLongBits(this.a[i]);
                hashCode = NumberUtils.hash(hashCode, (int) (doubleToLongBits ^ (doubleToLongBits >>> 32)));
            }
        }
        return hashCode;
    }

    public String toString() {
        return "Point [m_attributes=" + Arrays.toString(this.a) + ", m_description=" + this.m_description + "]";
    }

    @Override // com.esri.core.geometry.Geometry
    public boolean isValid() {
        return !isEmpty();
    }
}
